package org.karelun.gef.figure;

import org.eclipse.draw2d.BorderLayout;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.Shape;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.graphics.Color;

public class StateChoiceFigure extends NodeFigure {

	private class ChoiceShape extends Shape{
    	
		protected void fillShape(Graphics graphics) {
			Rectangle r = this.getBounds();
			Rectangle r1=new Rectangle(r.x, r.y, r.width-1 ,r.height-1);
			
			graphics.fillPolygon(new int[] {r1.x,r1.y+r.height/2, r1.x+r.width/2, r1.y,
                                r1.x+r.width-1, r1.y+r.height/2, r1.x+r.width/2, r1.y+r.height});	
		}		
		protected void outlineShape(Graphics graphics) {
		}
	}	
	
	private ChoiceShape choice=null;
	
	public StateChoiceFigure() {
		super();
		label=new Label();
	    BorderLayout layout = new BorderLayout();
		setLayoutManager(layout);
		
		choice= new ChoiceShape();
		choice.add(label);
		setOpaque(true);
		add(choice,BorderLayout.CENTER);
	}

    public void setBounds(Rectangle rect) {
        super.setBounds(rect);
        this.label.setBounds(rect);
    }

	@Override
	protected void setBGColor(Color color) {
		if(choice==null)
			return;
		choice.setBackgroundColor(color);
	}
}